package com.damie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dadie.Dto.SiteDto;
import com.dadie.parame.SiteParame;
import com.damie.common.commonutils.R;
import com.damie.service.SiteService;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Delete;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alon
 * @since 2021-01-21
 */
@Api(value="controller",tags={"后台:站点管理"})
@RestController
@CrossOrigin("*")
@RequestMapping("/boss/site")
public class SiteController {

    @Resource
    private SiteService service;

    @PostMapping("selectAllSite")
    @ApiOperation("分页查询所有正式站点的请求")
    public R selectAllSite(Integer index,Integer size,@RequestBody SiteParame siteParame){
        Page<SiteDto> siteDtoPage = service.selectAllSite(index, size, siteParame);
        return R.ok().data("site",siteDtoPage);
    }

    @PostMapping("selectAllAddSite")
    @ApiOperation("分页查询所有正在申请成为站点的请求")
    public R selectAllAddSite(Integer index,Integer size,@RequestBody SiteParame siteParame){
        Page<SiteDto> siteDtoPage = service.selectAllAddSite(index, size, siteParame);
        return R.ok().data("site",siteDtoPage);
    }

    @GetMapping("selectByAddSite")
    @ApiOperation("查询某个id的站点")
    public R selectByAddSite(String siteId){
        SiteDto siteDtos = service.selectByAddSite(siteId);
        return R.ok().data("site",siteDtos);
    }

    @GetMapping("approved")
    @ApiOperation("通过指定ID站点的申请")
    public R approved(String siteId){
        SiteDto approved = service.approved(siteId);
        return R.ok().data("site",approved);
    }
    @GetMapping("delete")
    @ApiOperation("删除没通过申请的ID站点")
    public R delete(String siteId){
        SiteDto approved = service.delete(siteId);
        return R.ok().data("site",approved);
    }
    @PostMapping("updateSite")
    @ApiOperation("根据站点id进行修改")
    public R updateById(@RequestBody SiteParame siteParame){
        SiteDto siteDto = service.updateByIds(siteParame);
        return R.ok().data("site",siteDto);
    }
}

